<template>

  <div v-if="query.bisAdlXmName === ''">
    <div class="my-code">点击ADL项目名称查看详情</div>
  </div>
  <div v-else>
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
        <el-input v-model="query.bisAdlXmId" clearable placeholder="选项名称" style="width: 185px;" class="filter-item" @keyup.enter.native="toQuery" />
        <rrOperation />
      </div>
      <!--表单组件-->
      <el-dialog append-to-body :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="500px">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px">
          <el-form-item label="选项名称" prop="bisAdlXmxxName">
            <el-input v-model="form.bisAdlXmxxName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="选项分数" prop="bisAdlXmxxFs">
            <el-input v-model="form.bisAdlXmxxFs" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="排序" prop="bisAdlXmxxPx">
            <el-input v-model="form.bisAdlXmxxPx" style="width: 370px;" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.status.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" highlight-current-row style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column label="所属项目">
          {{ query.bisAdlXmName }}
        </el-table-column>
        <el-table-column prop="bisAdlXmxxName" label="选项名称" />
        <el-table-column prop="bisAdlXmxxFs" label="选项分数" />
        <el-table-column prop="bisAdlXmxxPx" label="排序" />
        <el-table-column v-if="checkPer(['admin','adlXmxx:edit','adlXmxx:del'])" label="操作" width="150px" align="center">
          <template slot-scope="scope">
            <udOperation
              :data="scope.row"
              :permission="permission"
            />
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudAdlXmxx from '@/api/business/adlXmxx'
import CRUD, { presenter, header, form } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'

const defaultForm = { bisAdlXmxxId: null, bisAdlXmxxName: null, bisAdlXmxxFs: null, bisAdlXmxxPx: null, ywlx: null, lrr: null, lrrxm: null, lrbm: null, lrbmmc: null, lrsj: null, gxr: null, gxrxm: null, gxbm: null, gxbmmc: null, gxsj: null, sfyx: null, bz: null }
export default {
  components: { pagination, rrOperation, udOperation },
  mixins: [presenter(), header(),
    form(function() {
      return Object.assign({ adlXm: { bisAdlXmId: this.bisAdlXmId }}, defaultForm)
    })],
  cruds() {
    return CRUD({ title: 'ADL项目选项', url: 'api/adlXmxx', query: { bisAdlXmName: '', bisAdlXmId: '' }, sort: 'bisAdlXmxxPx,desc', crudMethod: { ...crudAdlXmxx }})
  },
  data() {
    return {
      queryFlag: false,
      bisAdlXmId: null,
      permission: {
        add: ['admin', 'adlPc:add'],
        edit: ['admin', 'adlPc:edit'],
        del: ['admin', 'adlPc:del']
      },
      rules: {
        bisAdlXmxxName: [
          { required: true, message: '选项名称不能为空', trigger: 'blur' }
        ],
        bisAdlXmxxFs: [
          { required: true, message: '选项分数不能为空', trigger: 'blur' }
        ],
        bisAdlXmxxPx: [
          { required: true, message: '排序不能为空', trigger: 'blur' }
        ]
      },
      queryTypeOptions: [
        { key: 'bisAdlXmxxName', display_name: '选项名称' }
      ]
    }
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return this.queryFlag
    }
  }
}
</script>

<style scoped>

</style>
